<!DOCTYPE html>
<html>
<body>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>

<input id="tabindex30" tabindex="30">
<input id="tabindex20-1" tabindex="20">
<input id="time-with-tabindex20" tabindex="20" type="time">
<input id="tabindex20-3" tabindex="20">
<input id="tabindex10" tabindex="10">

<script>
if (!window.eventSender || !window.internals)
    debug('This requires DRT/WRT.');

var firstSubField = "-webkit-datetime-edit-hour-field";
var lastSubField = "-webkit-datetime-edit-ampm-field";
var tab = '\t';
var shift = ['shiftKey'];

$('tabindex10').focus();
var shadowRoot = internals.shadowRoot($('time-with-tabindex20'));

debug('Forword:');
shouldBeEqualToString('eventSender.keyDown(tab); document.activeElement.id', 'tabindex20-1');
shouldBeEqualToString('eventSender.keyDown(tab); document.activeElement.id', 'time-with-tabindex20');
shouldBe('internals.shadowPseudoId(shadowRoot.activeElement)', 'firstSubField');
shouldBe('eventSender.keyDown(tab); eventSender.keyDown(tab); internals.shadowPseudoId(shadowRoot.activeElement)', 'lastSubField');
shouldBeEqualToString('eventSender.keyDown(tab); document.activeElement.id', 'tabindex20-3');
shouldBeEqualToString('eventSender.keyDown(tab); document.activeElement.id', 'tabindex30');

debug('');
debug('Backword:');
shouldBeEqualToString('eventSender.keyDown(tab, shift); document.activeElement.id', 'tabindex20-3');
shouldBeEqualToString('eventSender.keyDown(tab, shift); document.activeElement.id', 'time-with-tabindex20');
shouldBe('internals.shadowPseudoId(shadowRoot.activeElement)', 'lastSubField');
shouldBe('eventSender.keyDown(tab, shift); eventSender.keyDown(tab, shift); internals.shadowPseudoId(shadowRoot.activeElement)', 'firstSubField');
shouldBeEqualToString('eventSender.keyDown(tab, shift); document.activeElement.id', 'tabindex20-1');


</script>
</body>
</html>
